package Object_test;

/**
 * @Grup:Object_test
 * @Auther:cola
 * @Data:2021/3/29-2021-03-22:20
 * @version:1.0
 */
public class OneToManyDemo {
    public static void main(String[] args) {

        Teacher t1=new Teacher("白老师",18,"女");
        Student s1=new Student("肖里",5,"男");
        Student s2=new Student("肖王",6,"女");
        Student s3=new Student("肖站",9,"女");

        //关联关系
        t1.getStudents().add(s1);
        t1.getStudents().add(s2);
        t1.getStudents().add(s3);

        s1.setTeacher(t1);
        s2.setTeacher(t1);
        s3.setTeacher(t1);
        print(t1);
    }
    private static void print(Teacher t1){
        System.out.println(t1.getName());
        /*for (Student s:t1.getStudents()){
            System.out.println(s);
        }*/
        t1.getStudents().forEach(student -> System.out.println(student));
    }
}
